package cn.star.jots.filmSubject.service.impl;

import cn.star.jots.filmSubject.mapper.FSMapper;
import cn.star.jots.filmSubject.pojo.dto.FilmSubjectQuery;
import cn.star.jots.filmSubject.pojo.dto.FilmSubjectSaveParam;
import cn.star.jots.filmSubject.pojo.entity.FilmSubject;
import cn.star.jots.filmSubject.pojo.vo.FilmSubjectVO;
import cn.star.jots.filmSubject.service.FSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class FSServiceImpl implements FSService {
    @Autowired
    FSMapper fsMapper;

    @Override
    public List<FilmSubjectVO> selectAll(FilmSubjectQuery filmSubjectQuery) {
        log.debug("查询电影专题,参数:{}", filmSubjectQuery);
        return fsMapper.selectAll(filmSubjectQuery);
    }

    @Override
    public void save(FilmSubjectSaveParam filmSubjectSaveParam) {
        log.debug("保存电影专题,参数:{}", filmSubjectSaveParam);
        List<Long> filmIds = filmSubjectSaveParam.getFilmId();
        for (Long filmId : filmIds) {
            FilmSubject filmSubject = new FilmSubject();
            filmSubject.setFilmId(filmId);
            filmSubject.setSubjectId(filmSubjectSaveParam.getSubjectId());
            filmSubject.setCreateTime(new Date());
            fsMapper.insert(filmSubject);
        }
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除专题里的电影:id={}", id);
        fsMapper.deleteById(id);
    }
}
